package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.EventBean;
import com.mdx.service.IEventService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;

//事件
@RestController
@RequestMapping("event")
public class EventController {
    @Resource
    private IEventService eventService;

    //查询所有事件信息
    @RequestMapping("findAll")
    public IPage<EventBean> findAllEvent(
            @RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
            @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return eventService.findByItem(pageNO,pageSize,null,null,null,null,null);
    }

    //添加
    @RequestMapping("add")
    public String add(EventBean eventBean){
        eventService.save(eventBean);
        return "ok";
    }

    //根据id查询事件信息
    @RequestMapping("findById")
    public EventBean findById(int eventId){
        return eventService.findById(eventId);
    }

    //根据Id更改灾情状态、防治方案
    @RequestMapping("update")
    public String update(int eventId,String disasterStage,String preventionScheme){
        eventService.updateById(eventId,disasterStage,preventionScheme);
        return "ok";
    }

    //模糊查询
    @RequestMapping("findByItem")
    public IPage<EventBean> findByItem(
            @RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
            @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
            String eventName, String disasterStage, String regionName,
            LocalDate start,
            LocalDate end) {
        return eventService.findByItem(pageNO,pageSize,eventName,disasterStage,regionName,start,end);
    }
}
